#include <stdio.h>
#include <stdlib.h>  /* exit() 函数 */
#include <ctype.h>
void input ();
void output ();
int i=0,j=0,a1,a2,a3;
char sentence[810][20];
double ave; 
FILE *pdf;

int main()
{ 
   pdf = fopen("stud.csv", "w");
   if(pdf == NULL)
   {
      printf("Error!");
      exit(1);
   }

   printf("please enter your data\n");
   printf("and press 'ctrl + z' to end your input:\n");
   input ();
   output(); 
  
   fclose(pdf);
 
   return 0;
}
void input()
{
    char c;
    while((c=getchar())!=EOF){
        if(isdigit(c)){
            sentence[i][j++]=c;
        }
        else{
            i++;
            j=0;
            continue;
        }
    }
}
void output(){
    i--;
    for(int k=0;k<=i;k++){
        if(k%4==0){
            fprintf(pdf,"%s,",sentence[k]);
        }
        else if(k%4==1){
            a1=atoi(sentence[k++]);
            a2=atoi(sentence[k++]);
            a3=atoi(sentence[k]);
            ave=(a1+a2+a3)/3.0;
            fprintf(pdf,"%d,%d,%d,%.2llf\n",a1,a2,a3,ave);
        }
    }
}

